﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using TinySteamWrapper;

namespace WpfDemoApp
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

        }

        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            if (TextAPIKey.Text == null || TextAPIKey.Text.Equals(""))
            {
                MessageBox.Show("Please enter your API Key to load a profile.", "No credentials found", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            SteamManager.SteamAPIKey = TextAPIKey.Text;

            if(TextBoxUsername.Text != null && !TextBoxUsername.Text.Equals("")) {
                ButtonSearch.Visibility = System.Windows.Visibility.Collapsed;
                TextLoading.Visibility = System.Windows.Visibility.Visible;

                long steamID = await SteamManager.GetSteamIDByName(TextBoxUsername.Text);

                if (steamID != 0)
                {
                    SteamProfile profile = await SteamManager.GetSteamProfileByID(steamID);
                    if (profile == null)
                    {
                        MessageBox.Show("Steam profile could not be found.", "No profile found", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }

                    this.DataContext = profile;

                    await SteamManager.LoadGamesForProfile(profile);
                }
                else
                {
                    MessageBox.Show("Steam profile could not be found.", "No profile found", MessageBoxButton.OK, MessageBoxImage.Error);
                }

                TextLoading.Visibility = System.Windows.Visibility.Collapsed;
                ButtonSearch.Visibility = System.Windows.Visibility.Visible;
            }
        }
    }
}
